package com.ph.controller;

import com.ph.pojo.Result;
import com.ph.pojo.Role;
import com.ph.service.RoleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
//@CrossOrigin
@RestController
@RequestMapping("sys/role")
@Slf4j
public class RoleController {
    @Autowired
    private RoleService roleService;

    @RequiresUser
    @GetMapping
    public Result<List<Role>> findAll(){
        List<Role> roles = roleService.findByTree();
        for (Role role : roles){
            role.setName(role.getName() + ":"  + role.getId());
            for (Role role1 : role.getRoles()){
                role1.setName(role1.getName() + ":"  + role1.getId());
            }
        }
        return Result.success(roles);
    }
}
